package com.sam.im.heiqun.entities.beans;

import android.os.Parcel;
import android.os.Parcelable;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.constant.Constant;
import com.sam.im.heiqun.entities.ImMessage;
import com.sam.im.heiqun.uis.activities.ChatActivity;
import com.sam.im.heiqun.utils.ToolsUtils;

/**
 * Created by zhangqiang on 2018/7/25.
 */
public class CollectInfo implements Parcelable {

    private String category;
    private String url;
    private String content;
    private String fromname;
    private String fromid;
    private String userid;

    public static CollectInfo fromImMessage(ImMessage imMessage) {

        String colactiontype = null;
        Integer messageType = imMessage.getMessageType();
        if (messageType == Constant.MESSAGE_TYPR_TEXT | messageType == Constant.MESSAGE_TYPR_BQEMOJI) {
            colactiontype = "1";
        } else if (messageType == Constant.MESSAGE_TYPR_IMAGE) {
            colactiontype = "2";
        } else if (messageType == Constant.MESSAGE_TYPR_VOICE) {
            colactiontype = "3";
        } else if (messageType == Constant.MESSAGE_TYPR_VEDIO) {
            colactiontype = "4";
        } else {
            return null;
        }

        CollectInfo collectInfo = new CollectInfo();
        collectInfo.setUrl(imMessage.getImageIconUrl());
        collectInfo.setFromname(imMessage.getFromname());
        collectInfo.setFromid(String.valueOf(imMessage.getFromid()));
        collectInfo.setCategory(colactiontype);
        collectInfo.setContent(imMessage.getContent());
        return collectInfo;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getFromname() {
        return fromname;
    }

    public void setFromname(String fromname) {
        this.fromname = fromname;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getFromid() {
        return fromid;
    }

    public void setFromid(String fromid) {
        this.fromid = fromid;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.category);
        dest.writeString(this.url);
        dest.writeString(this.content);
        dest.writeString(this.fromname);
        dest.writeString(this.fromid);
        dest.writeString(this.userid);
    }

    public CollectInfo() {
    }

    protected CollectInfo(Parcel in) {
        this.category = in.readString();
        this.url = in.readString();
        this.content = in.readString();
        this.fromname = in.readString();
        this.fromid = in.readString();
        this.userid = in.readString();
    }

    public static final Parcelable.Creator<CollectInfo> CREATOR = new Parcelable.Creator<CollectInfo>() {
        @Override
        public CollectInfo createFromParcel(Parcel source) {
            return new CollectInfo(source);
        }

        @Override
        public CollectInfo[] newArray(int size) {
            return new CollectInfo[size];
        }
    };
}
